# -*- coding: utf-8 -*-
# !/usr/bin/env python
from utils.mysql_utils import query_to_list

def query_resource_user(resource_user_ids=''):
    sql_parameter = []

    if resource_user_ids:
        sql_fragment = "WHERE a.resource_user_ids IN (%s)" % ','.join(['%s'] * len(resource_user_ids))
        sql_parameter = resource_user_ids
    else:
        sql_fragment = ''

    sql = """
    SELECT a.*,b.sys_code_name AS resource_user_permission_text FROM resource_user a
    LEFT JOIN sys_code b ON a.resource_user_permission_code = b.sys_code AND b.sys_code_type = "resource_user_permission_type"
    %s
    AND a.`status` = 1
    """%sql_fragment
    data = query_to_list(sql, sql_parameter, False)

    return data

def query_resource_user_info(resource_user_id=''):
    sql_parameter = []

    if resource_user_id:
        sql_fragment = "WHERE a.resource_user_id = %s"
        sql_parameter.append(resource_user_id)
    else:
        sql_fragment = ''

    sql = """
    SELECT a.* FROM resource_user a
    %s
    """%sql_fragment
    data = query_to_list(sql, sql_parameter, True)

    return data